Skip to content

coremidi: fix hang on shutdown and on quick restart - #1028

Open
zinc75 wants to merge 2 commits into
jackaudio:developfrom
zinc75:fix/coremidi-shutdown-hang
Open

zinc75 wants to merge 2 commits into
jackaudio:developfrom
zinc75:fix/coremidi-shutdown-hang

Conversation

@zinc75

@zinc75 zinc75 commented Oct 29, 2026

Copy link
Copy Markdown

Hi @falkTX,

This fixes #1027 .

The CoreMIDI threads were stopped with Kill(), which cannot wake a thread blocked in CFRunLoopRun() or sem_wait(). They are now asked to stop and joined.

Once that worked, I also noticed a quick restart failed with port_name "system_midi:capture_1" already exists. The previous server's endpoints disappearing triggered Restart() while the new server was still in Attach(). Notifications are now ignored while closing and until Start() is done, so a device change in that short window is only seen at the next notification.

I also added tests/jack_coremidi_shutdown_test.sh, which starts and stops jackd -X coremidi -d dummy a few times in a row. It fails on current develop and passes with this change.

I tested it on macOS 26.7 (Apple Silicon) with the dummy and CoreAudio drivers.

Not tried: real MIDI hardware (I don't have any), long runs, and Intel, but I don't see any reason why it should not work on Intel also.

Feel free to ask me for changes if you see things differently. Thanks!

Kill() cannot interrupt a thread blocked in CFRunLoopRun() or sem_wait(),
so jackd never exited when stopped. Stop the threads cooperatively instead.

Also ignore CoreMIDI notifications until the driver is started and while
it is closing, so Restart() cannot run alongside Attach().
Start and stop jackd with the coremidi driver several times in a row.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coremidi: jackd does not exit when stopped (macOS)

1 participant